import unittest
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import os
from ddt import ddt, file_data

# 怎么把public/common中的方法导入进来
pathmf = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))+"\\dataa\\datagerenusertrue.json"
pamf=os.path.abspath(os.path.dirname(os.path.dirname(__file__)))+"\\dataa\\w.jpg"
from mfxt.publick.common import denlu, tuichu, quitbrower

# 创建单元测试类
@ddt
class mifeng_geren_user_true(unittest.TestCase):
    def setUp(self):
        # 创建浏览器对象
       self.driver = webdriver.Chrome()
       self.driver.maximize_window()
       self.driver.implicitly_wait(10)
       self.driver.get("http://39.101.167.251/qftest/")
       denlu(self.driver)

    @file_data(pathmf)
    #写一条正向测试用例
    def test_mifeng_geren_user_true(self,n,q,ge,expect):
        self.driver.find_element(By.LINK_TEXT,'个人资料').click()
        self.driver.find_element(By.XPATH,'//*[@id="avatar-form"]/input[1]').send_keys(pamf)
        self.driver.find_element(By.XPATH,'//*[@id="save-avatar-btn"]').click()
        self.driver.find_element(By.NAME, "nickname").clear()
        self.driver.find_element(By.NAME,"nickname").send_keys(n)
        self.driver.find_element(By.ID, "qq").clear()
        self.driver.find_element(By.ID,"qq").send_keys(q)
        self.driver.find_element(By.NAME,"gender").click()
        self.driver.find_element(By.XPATH, '//*[@id="birth_year"]/option[78]').click()
        self.driver.find_element(By.XPATH, '//*[@id="birth_month"]/option[12]').click()
        self.driver.find_element(By.XPATH, '//*[@id="birth_day"]/option[13]').click()
        self.driver.find_element(By.ID, "signature").clear()
        self.driver.find_element(By.ID,"signature").send_keys(ge)
        self.driver.find_element(By.XPATH,'//*[@id="profile-form"]/div/button').click()

        #断言
        expect_value = expect
        actual_value = self.driver.find_element(By.XPATH, '/html/body/div/div/h3').text
        self.assertEqual(expect_value, actual_value, "实际结果和预期结果不一致！！")
        time.sleep(5)

    def tearDown(self):
        tuichu(self.driver)

if __name__ == '__main__':
    unittest.main()
